#ifndef __NET_TABLE_H__
#define __NET_TABLE_H__

#include "ynet_net.h"

int netable_init(int daemon);
int netable_destroy(void);

int netable_accept(const ynet_net_info_t *info, net_handle_t *sock);

int netable_connect_info(net_handle_t *nh, const ynet_net_info_t *info, int force);
int netable_updateinfo(const ynet_net_info_t *info);
int netable_getinfo(const nid_t *nid, ynet_net_info_t *info, uint32_t *buflen);

int netable_connected(const nid_t *nid);
int netable_connectable(const nid_t *nid, int force);

int netable_add_reset_handler(const nid_t *nid, void (*handler)(const nid_t *, const char *));
void netable_close(const nid_t *nid, const char *resion, const time_t *ltime);
void netable_close_withrpc(const sockid_t *sockid, const nid_t *nid, const char *why);

const char *netable_rname(const void *_nh);
const char *netable_rname_nid(const nid_t *nid);
int netable_rname1(const nid_t *nid, char *name);

int netable_getname(const nid_t *nid, char *name);
int netable_gethost(const nid_t *nid, char *name);
int netable_getsock(const nid_t *nid, sockid_t *sockid);

time_t netable_conn_time(const nid_t *nid);
void netable_ltime_reset(const nid_t *nid, time_t ltime, const char *why);

//void netable_closewait(const net_handle_t *nh, const char *why);
void netable_select(const nid_t *nids, int count, nid_t *nid);
void netable_sort(nid_t *nid, int count);

void netable_load_update(const nid_t *nid, uint64_t load);
int netable_update_retry(const nid_t *nid);

void netable_iterate(void);
int netable_dump_hb_timeout(char *lname);
void netable_update(const nid_t *nid);
time_t netable_last_update(const nid_t *nid);
int netable_start();

#endif
